package com.acegear.horizon.domain.models.jpa;

import com.acegear.horizon.domain.models.AbstractVerify;
import com.acegear.horizon.utils.StringUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
 * Created by wangsike on 2016/12/10.
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
public class EmailVerify extends AbstractVerify {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @JsonIgnore
    private Long id;

    @Column
    private String email;

    @Column
    private String code;

    @Column
    private Long expireAt;

    @Column
    private Long verifyAt;

    @CreatedDate
    @Column
    private Long createAt;

    @LastModifiedDate
    @Column
    private Long updateAt;

    public EmailVerify() {

    }

    public EmailVerify(String email) {
        this.email = email;
        this.code = StringUtil.randomNumeric(6);
        this.expireAt = System.currentTimeMillis() + 3600 * 1000;
        this.verifyAt = 0L;
    }

    public Long getCreateAt() {
        return createAt;
    }

    public Long getUpdateAt() {
        return updateAt;
    }

    public Long getId() {

        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getExpireAt() {
        return expireAt;
    }

    public void setExpireAt(Long expireAt) {
        this.expireAt = expireAt;
    }

    public Long getVerifyAt() {
        return verifyAt;
    }

    public void setVerifyAt(Long verifyAt) {
        this.verifyAt = verifyAt;
    }
}
